home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / TNC2.C < prev    next >
C/C++ Source or Header  |  1990-04-28  |  35KB  |  1,366 lines

  1. /* TNC-2 emulator for use by RLI or MBL bbs (or other programs) */
  2.  
  3. #include <ctype.h>
  4. #include <time.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "iface.h"
  8. #include "timer.h"
  9. #include "ax25.h"
  10. #include "lapb.h"
  11. #include "kiss.h"
  12. #include "slip.h"
  13. #include "tnc2.h"
  14.  
  15. #undef    ALLCMDS        1        /* include unsupported cmds? */
  16. #define BEACON        1        /* include BEACON possibility? */
  17.  
  18. struct tnc *tnc2s = NULLTNC;        /* TNC controlblocks */
  19. static void tnc2_recv();        /* upcall handlers */
  20.  
  21. /* TNC commands supported by the emulator */
  22. static void dotnconmode(),dotnconnect(),dotnconverse(),
  23.     dotncstatus(),dotndaytime(),dotndiscon(),dotndisplay(),
  24.     dotnmycall(),dotnrestart(),dotntrans(),dotnunproto();
  25.  
  26. void dotnmheard(),dotnreset();
  27.  
  28. static struct tnccommand tnccommands[] =
  29. {
  30.     "8BITCONV", TC_ON_OFF,    0,    NULLVFP,
  31. #ifdef ALLCMDS
  32.     "AX25L2V2", TC_ON_OFF,    1,    NULLVFP,    /* not used */
  33. #endif
  34.     "AUTOLF",    TC_ON_OFF,    2,    NULLVFP,
  35. #ifdef ALLCMDS
  36.     "AWLEN",    TC_DECVAL,    3,    NULLVFP,    /* not used */
  37.     "AXDELAY",    TC_DECVAL,    4,    NULLVFP,    /* not used */
  38.     "AXHANG",    TC_DECVAL,    5,    NULLVFP,    /* not used */
  39. #endif
  40. #if (defined(BEACON) || defined(ALLCMDS))
  41.     "BEACON",    TC_TIMER,    0,    (void (*)()) 10000,
  42. #endif
  43.     "BBSMSGS",    TC_ON_OFF,    55,    NULLVFP,
  44.     "BKONDEL",    TC_ON_OFF,    6,    NULLVFP,
  45. #if (defined(BEACON) || defined(ALLCMDS))
  46.     "BTEXT",    TC_TEXT,    0,    NULLVFP,
  47. #endif
  48. #ifdef ALLCMDS
  49.     "BUDLIST",    TC_ON_OFF,    7,    NULLVFP,    /* not used */
  50. #endif
  51.     "CONNECT",    TC_EXEC,    0,    dotnconnect,
  52.     "CBELL",    TC_ON_OFF,    8,    NULLVFP,
  53. #ifdef ALLCMDS
  54.     "CONPERM",    TC_ON_OFF,    9,    NULLVFP,    /* not used */
  55.     "CHECK",    TC_DECVAL,    10,    NULLVFP,    /* not used */
  56.     "CLKADJ",    TC_DECVAL,    11,    NULLVFP,    /* not used */
  57. #endif
  58.     "CMDTIME",    TC_DECVAL,    12,    NULLVFP,
  59.     "CMSG",    TC_ON_OFF,    13,    NULLVFP,
  60.     "CMSGDISC", TC_ON_OFF,    14,    NULLVFP,
  61.     "CPACTIME", TC_ON_OFF,    15,    NULLVFP,
  62.     "CR",    TC_ON_OFF,    16,    NULLVFP,
  63.     "CSTATUS",    TC_EXEC,    0,    dotncstatus,
  64.     "CTEXT",    TC_TEXT,    1,    NULLVFP,
  65.     "CANLINE",    TC_HEXVAL,    17,    NULLVFP,
  66.     "COMMAND",    TC_HEXVAL,    18,    NULLVFP,
  67. #ifdef ALLCMDS
  68.     "CALSET",    TC_DECVAL,    19,    NULLVFP,    /* not used */
  69. #endif
  70.     "CANPAC",    TC_HEXVAL,    20,    NULLVFP,
  71.     "CONOK",    TC_ON_OFF,    21,    NULLVFP,
  72.     "CONMODE",    TC_MISC,    0,    dotnconmode,
  73.     "CONSTAMP", TC_ON_OFF,    22,    NULLVFP,
  74.     "CONVERSE", TC_EXEC,    0,    dotnconverse,
  75.     "DISCONNE", TC_EXEC,    0,    dotndiscon,
  76.     "DAYTIME",    TC_EXEC,    0,    dotndaytime,
  77.     "DAYUSA",    TC_ON_OFF,    23,    NULLVFP,
  78.     "DELETE",    TC_ON_OFF,    24,    NULLVFP,
  79. #ifdef ALLCMDS
  80.     "DWAIT",    TC_DECVAL,    25,    NULLVFP,    /* not used */
  81.     "DIGIPEAT", TC_ON_OFF,    26,    NULLVFP,    /* not used */
  82. #endif
  83.     "DISPLAY",    TC_EXEC,    0,    dotndisplay,
  84.     "ECHO",    TC_ON_OFF,    27,    NULLVFP,
  85. #ifdef ALLCMDS
  86.     "ESCAPE",    TC_ON_OFF,    28,    NULLVFP,    /* not used */
  87. #endif
  88.     "FLOW",    TC_ON_OFF,    29,    NULLVFP,
  89. #ifdef ALLCMDS
  90.     "FRACK",    TC_DECVAL,    30,    NULLVFP,    /* not used */
  91.     "FULLDUP",    TC_ON_OFF,    31,    NULLVFP,    /* not used */
  92.     "HEADERLN", TC_ON_OFF,    32,    NULLVFP,    /* not used */
  93.     "HEALLED",    TC_ON_OFF,    33,    NULLVFP,    /* not used */
  94.     "HID",    TC_ON_OFF,    34,    NULLVFP,    /* not used */
  95.     "ID",    TC_EXEC,    0,    NULLVFP,
  96. #endif
  97.     "K",    TC_EXEC,    0,    dotnconverse,    /* ALIAS for CONVERSE */
  98.     "KISS",    TC_ON_OFF,    76,    NULLVFP,
  99.     "KISSRX",    TC_DECVAL,    77,    NULLVFP,
  100. #ifdef ALLCMDS
  101.     "LCOK",    TC_ON_OFF,    35,    NULLVFP,    /* not used */
  102. #endif
  103.     "LFADD",    TC_ON_OFF,    36,    NULLVFP,
  104.     "LFIGNORE", TC_ON_OFF,    37,    NULLVFP,
  105. #ifdef ALLCMDS
  106.     "LCALLS",    TC_TEXT,    2,    NULLVFP,    /* not used */
  107.     "LCSTREAM", TC_ON_OFF,    38,    NULLVFP,    /* not used */
  108. #endif
  109.     "MONITOR",    TC_ON_OFF,    39,    NULLVFP,    /* not used, incl for BBS */
  110. #ifdef ALLCMDS
  111.     "MALL",    TC_ON_OFF,    40,    NULLVFP,    /* not used */
  112.     "MCON",    TC_ON_OFF,    41,    NULLVFP,    /* not used */
  113.     "MFILTER",    TC_MISC,    1,    NULLVFP,    /* not used */
  114. #endif
  115.     "MHEARD",    TC_EXEC,    0,    dotnmheard,
  116. #ifdef ALLCMDS
  117.     "MHCLEAR",    TC_EXEC,    0,    NULLVFP,
  118.     "MRPT",    TC_ON_OFF,    42,    NULLVFP,    /* not used */
  119.     "MSTAMP",    TC_ON_OFF,    43,    NULLVFP,    /* not used */
  120. #endif
  121.     "MYCALL",    TC_EXEC,    0,    dotnmycall,
  122. #ifdef ALLCMDS
  123.     "MYALIAS",    TC_TEXT,    3,    NULLVFP,    /* not used */
  124.     "MAXFRAME", TC_DECVAL,    44,    NULLVFP,    /* not used */
  125.     "MCOM",    TC_ON_OFF,    45,    NULLVFP,    /* not used */
  126. #endif
  127.     "NEWMODE",    TC_ON_OFF,    46,    NULLVFP,
  128.     "NOMODE",    TC_ON_OFF,    47,    NULLVFP,
  129. #ifdef ALLCMDS
  130.     "NUCR",    TC_ON_OFF,    48,    NULLVFP,    /* not used */
  131.     "NULF",    TC_ON_OFF,    49,    NULLVFP,    /* not used */
  132.     "NULLS",    TC_DECVAL,    50,    NULLVFP,    /* not used */
  133. #endif
  134.     "PACLEN",    TC_DECVAL,    51,    NULLVFP,
  135. #ifdef ALLCMDS
  136.     "PARITY",    TC_DECVAL,    52,    NULLVFP,    /* not used */
  137. #endif
  138.     "PASS",    TC_HEXVAL,    53,    NULLVFP,
  139. #ifdef ALLCMDS
  140.     "PASSALL",    TC_ON_OFF,    54,    NULLVFP,    /* not used */
  141. #endif
  142.     "PACTIME",    TC_TIMER,    1,    (void (*)()) 100,
  143. #ifdef ALLCMDS
  144.     "RETRY",    TC_DECVAL,    56,    NULLVFP,    /* not used */
  145. #endif
  146.     "REDISPLA", TC_HEXVAL,    57,    NULLVFP,
  147. #ifdef ALLCMDS
  148.     "RECONNEC", TC_EXEC,    0,    NULLVFP,
  149.     "RESPTIME", TC_DECVAL,    58,    NULLVFP,    /* not used */
  150. #endif
  151.     "RESTART",    TC_EXEC,    0,    dotnrestart,
  152.     "RESET",    TC_EXEC,    0,    dotnreset,
  153.     "RXBLOCK",    TC_ON_OFF,    59,    NULLVFP,
  154. #ifdef ALLCMDS
  155.     "SCREENLN", TC_DECVAL,    60,    NULLVFP,    /* not used */
  156. #endif
  157.     "SENDPAC",    TC_HEXVAL,    61,    NULLVFP,
  158.     "START",    TC_HEXVAL,    62,    NULLVFP,
  159.     "STOP",    TC_HEXVAL,    63,    NULLVFP,
  160. #ifdef ALLCMDS
  161.     "STREAMSW", TC_HEXVAL,    64,    NULLVFP,    /* not used */
  162.     "STREAMCA", TC_ON_OFF,    65,    NULLVFP,    /* not used */
  163.     "STREAMDB", TC_ON_OFF,    66,    NULLVFP,    /* not used */
  164. #endif
  165.     "TRANS",    TC_EXEC,    0,    dotntrans,
  166. #ifdef ALLCMDS
  167.     "TRIES",    TC_EXEC,    0,    NULLVFP,    /* not used */
  168. #endif
  169.     "TRFLOW",    TC_ON_OFF,    67,    NULLVFP,
  170. #ifdef ALLCMDS
  171.     "TRACE",    TC_ON_OFF,    68,    NULLVFP,    /* not used */
  172.     "TXDELAY",    TC_DECVAL,    69,    NULLVFP,    /* not used */
  173. #endif
  174.     "TXFLOW",    TC_ON_OFF,    70,    NULLVFP,
  175.     "TXUIFRAM", TC_ON_OFF,    78,    NULLVFP,
  176.     "UNPROTO",    TC_EXEC,    0,    dotnunproto,
  177. #ifdef ALLCMDS
  178.     "USERS",    TC_DECVAL,    71,    NULLVFP,    /* not used */
  179. #endif
  180.     "XFLOW",    TC_ON_OFF,    72,    NULLVFP,
  181. #ifdef ALLCMDS
  182.     "XMITOK",    TC_ON_OFF,    73,    NULLVFP,    /* not used */
  183. #endif
  184.     "XOFF",    TC_HEXVAL,    74,    NULLVFP,
  185.     "XON",    TC_HEXVAL,    75,    NULLVFP,
  186.     "",        0,        0,    NULLVFP
  187. };
  188.  
  189. static char def_params[] = {
  190.     0, 1, 1, 7, 0, 0, 1, 0, 0, 0, 30, 0, 1, 0, 0, 0,
  191.     1, 0x18, 0x03, 0, 0x19, /*1*/ 0, 0, 1, 0, 16, 1, 1, 0, 1, 3, 0,
  192.     0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 2, 1, 0, 0,
  193.     0, 0, 0, 128, 3, 0x16, 0, 0, 10, 0x12, 0, 0, 80, 0x0d, 0x11, 0x13,
  194.     0x7c, 0, 0, 0, 0, 30, 0, 1, 1, 1, 0x13, 0x11, 0, 1, 0
  195. };
  196.  
  197. char tnc2_prompt[] = "cmd:";
  198. static char tnc2_bad[] = "?bad\r";
  199. static char tnc2_call[] = "?call\r";
  200. static char tnc2_notenough[] = "?not enough\r";
  201. static char tnc2_toomany[] = "?too many\r";
  202. static char tnc2_was[] = "was ";
  203. static char tnc2_conrq[] = "*** connect request:";
  204. static char tnc2_bslcr[] = "\\\r";
  205. static char tnc2_cr[] = "\r";
  206. extern char *ax25mesgs[];
  207.  
  208. /* send message to client (BBS) */
  209. void
  210. tnc2_mesg (tnc2,s)
  211. register struct tnc *tnc2;
  212. register unsigned char *s;
  213.  
  214. {
  215.     while (*s) {
  216.     if (!tnc2_ochar(tnc2,*s))
  217.         break;
  218.  
  219.     if (*s++ == '\r' && tnc2->param[2])    /* AUTOLF */
  220.         if (!tnc2_ochar(tnc2,'\n'))
  221.         break;
  222.     }
  223. }
  224.  
  225. /* process character input in cooked mode, return 1 if line complete */
  226. int
  227. tnc2_line (tnc2,c)
  228. register struct tnc *tnc2;
  229. register char c;
  230.  
  231. {
  232.     if (tnc2->passc) {            /* prev was PASS char? */
  233.         tnc2->passc = 0;            /* clear the flag */
  234.         tnc2->linebuf[tnc2->linepos++] = c; /* store the passed char */
  235.         tnc2->linebuf[tnc2->linepos] = '\0';
  236.  
  237.         if (tnc2->param[27])        /* ECHO ON */
  238.         tnc2_mesg(tnc2,tnc2->linebuf + tnc2->linepos - 1); /* echo it */
  239.  
  240.         goto checkbuf;
  241.     }
  242.  
  243.     if (tnc2->param[17] && c == tnc2->param[17]) { /* CANLINE character */
  244.         while (tnc2->linepos > 0)
  245.         if (tnc2->linebuf[--(tnc2->linepos)] == '\r') {/* up to CR */
  246.             tnc2->linepos++;
  247.             break;
  248.         }
  249.  
  250.         tnc2_mesg(tnc2,tnc2_bslcr);
  251.         return TL_CANCEL;
  252.     }
  253.  
  254.     if (tnc2->param[18] && c == tnc2->param[18]) /* COMMAND character */
  255.         return TL_COMMAND;
  256.  
  257.     if (tnc2->param[20] && c == tnc2->p